

const http = require('http')
const url = require('url')
const fs = require('fs')
const path = require('path')
const server = http.createServer((req,res)=>{
    let urlObj = url.parse(req.url,true)
    // console.log(urlObj);
    res.setHeader('Content-Type','text/html;charset=utf8')
    if(req.url === '/login'){
        fs.readFile('./views/login.html','utf8',(err,data)=>{
            if(err){
                throw err
            }
            res.end(data)
        })
    }else if(urlObj.pathname === '/userLogin'){
        console.log(urlObj.query.uname);
        console.log(urlObj.query.pwd);
        res.end(`欢迎${urlObj.query.uname}登录，登录时间${new Date()}`)
    }
})

server.listen(3002,()=>{
    console.log(`server is running port:3002`);
})